//
//  WJWebImageShowController.m
//  JerryIos
//
//  Created by jerrywang on 2018/2/10.
//  Copyright © 2018年 王军. All rights reserved.
//

#import "WJWebImageShowController.h"

@interface WJWebImageShowController ()

@property (weak, nonatomic) IBOutlet UIImageView *imageView;
@property (strong, nonatomic) UIActivityIndicatorView *activityIndicator;

@end

@implementation WJWebImageShowController

- (UIActivityIndicatorView *)activityIndicator {
    if (!_activityIndicator) {
        _activityIndicator = [UIActivityIndicatorView.alloc initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
        _activityIndicator.center = self.imageView.center;
        _activityIndicator.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
//        _activityIndicator.backgroundColor = UIColor.blueColor;
        [self.imageView addSubview:_activityIndicator];
    }
    
    return _activityIndicator;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self configureView];
}

- (void)configureView {
    self.activityIndicator.hidden = NO;
    [self.activityIndicator startAnimating];
    
    __weak typeof(self) weakSelf = self;
    [self.imageView setOriginImage:[self.imageURL absoluteString]
                    thumbnailImage:nil
                       placeholder:[UIImage imageNamed:@"icon_home"]
                         completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
                            [weakSelf.activityIndicator stopAnimating];
                            weakSelf.activityIndicator.hidden = YES;
    }];
    
}


@end
